{% extends 'accounts/stats_asset_edit.html' %}

{% block tabs %}
  <li><a href="#repository" class="active"> Repository
  </a></li>
  {{ block.super }}
{% endblock %}

{% block tab-content %}
  <div id="repository" class="tabset_content">
    <h2 class="tabset_label">Repository</h2>

    <p>The {{ user_asset.asset|escape }} project can feed data to {{ site.name }} in any of the following ways:</p>

    <ol>
      <li>
        <p class="note">
          You may already be using a hosting service, like <a href="http://sourceforge.net">SourceForge.net</a>
          or <a href="http://gna.org">Gna!</a>, which provides <strong>built-in {{ site.name }} integration</strong>.
          Check with your hosting provider for details. You may need to ensure that {{ site.name }} and your hosting provider
          use the same project name.
        </p>
      </li>

      <li>
        <p class="note">
          You may <strong>install a client script</strong> in your project's source repository. This
          option provides the fastest response time and supports a variety of revision control systems.
	  Download a <a href="/doc/clients/">client script</a> and configure it for the
	  <span class="code">{{ user_asset.asset.get_name|escape }}</span> project.
        </p>
      </li>

      <li>
        <p class="note">
          If your project uses a public <a href="http://subversion.tigris.org/">Subversion</a> repository, the {{ site.name }}
          server can <strong>contact your repository directly</strong> and check for commits.
        </p>
        <p>
	  {{ form.use_repository }}
          <label class="checkbox" for="id_use_repository">Connect to a public Subversion repository</label>
        </p>

	<div id="repository_details">
	  <fieldset><legend>Basic Configuration</legend>

	    <div class="form-row wide">
	      <label for="id_location">Repository URL:</label>
	      {{ form.location }}
	      <p class="error">{{ form.errors.location.0 }}</p>
	    </div>

	    {% if user_asset.asset.repos %}
              <div class="form-row">
                <label>Ping address:</label>
		<div class="field"><span class="code">{{ user_asset.asset.repos.get_pinger_email|escape }}</span></div>
		<div class="help">(<a class="help" id="pinger_help_link">help</a>)</div>
		<div id="pinger_help_text">
	          <p class="note">
		    For best performance, {{ site.name }} needs to be notified by e-mail when a change is committed to this
		    repository. Send any message to this address in order to trigger an update.
		  </p>
		  <p class="note">
		    Many projects already have a commit mailing list which
		    can be used for this purpose. Alternatively, you can add this line to your
                    <a href="http://svnbook.red-bean.com/en/1.1/ch05s02.html#svn-ch-5-sect-2.1">post-commit hook</a>:
                  </p>
		  <p class="note">
                    <span class="code">echo "To: {{ user_asset.asset.repos.get_pinger_email|escape }}" | sendmail -t</span>
		  </p>
		</div>
              </div>
	      <p>
		{{ form.forward_pinger_mail }}
		<label class="checkbox" for="id_forward_pinger_mail">Forward mail from the ping address to all project owners</label>
		<blockquote class="note">
		  This setting may be useful to enable temporarily if you're trying to subscribe
		  the above email address to an existing mailing list, and you need to confirm the
		  subscription.
		</blockquote>
	      </p>
	      <p>
		{{ form.enable_polling }}
		<label class="checkbox" for="id_enable_polling">Poll for changes every</label>
		{{ form.poll_frequency }}
		{% if form.errors.poll_frequency %}
		   <span class="error">&laquo; {{ form.errors.poll_frequency.0 }}</span>
		{% endif %}
		minutes
		<blockquote class="note">
		  If you have no way of sending e-mail notifications, or if your e-mail notifications
		  may be unreliable, you can use polling as a backup. Note that this will increase the
		  load on your Subversion server, and you may have to wait several minutes for new commits
		  to be announced if you rely only on polling.
		</blockquote>
	      </p>
	    {% endif %}
	  </fieldset>

	  {% if user_asset.asset.repos %}
	    <fieldset><legend>Advanced Options</legend>

	      <div class="form-row">
		<label for="id_revision_url">Revision URL pattern:</label>
		{{ form.revision_url }}
		<p class="error">{{ form.errors.revision_url.0 }}</p>
		<div class="help">(<a class="help" id="rev_url_help_link">help</a>)</div>
		<div id="rev_url_help_text">
		  <p class="note">
		    This optional setting allows you to give each {{ site.name }} commit message a URL which points to additional
		    information about that change. These URLs show up on your project's
		    <a href="http://{{ request.META.HTTP_HOST }}/stats/{{ user_asset.asset.target.path|urlencode|escape }}">stats page</a>
		    and RSS feed, and they can optionally be displayed by IRC bots.
		    You can use this to integrate {{ site.name }} with tools
		    like <a href="http://websvn.tigris.org/">WebSVN</a> and <a href="http://trac.edgewall.org/">Trac</a>.
		  </p>
		  <p class="note">
		    Placeholders like <span class="code">{project}</span>, <span class="code">{author}</span>, and <span class="code">{revision}</span>
		    are substituted appropriately for each commit. For example:
		  </p>
		  <p class="note">
		    <span class="code">http://svn.sourceforge.net/viewvc/{project}?view=rev&amp;revision={revision}</span>
		  </p>
		</div>
	      </div>

	      <div class="form-row">
		<label for="id_path_regexes">Path regex list:</label>
		{{ form.path_regexes }}
		<p class="error">{{ form.errors.path_regexes.0 }}</p>
		<div class="help">(<a class="help" id="path_re_help_link">help</a>)</div>
		<div id="path_re_help_text" class="note">
		  <p>
		    This is a list of regular expressions, one per line, which lets {{ site.name }} automatically extract
		    branch and module information from file paths in your Subversion repository. Each regular
		    expression contains named groups for extracting module and/or branch names. Whitespace
		    in the pattern is ignored.
		  </p>
		  <p>
		    The regular expressions are tested in the order specified. If the regex matches every path
		    in the commit with identical results, the extracted information is added to the commit
		    and the matched portion of each path is removed.
		  </p>
		  <p>
		    For example, the following regex list would be
		    appropriate for repositories with paths of the form
		    "trunk/module-name/..."  and "branches/module-name/branch-name/...":
		  </p>
		  <p class="code">
		    ^trunk/ (?P&lt;module>[^/]+)/ <br />
		    ^(branches|tags)/ (?P&lt;module>[^/]+)/ (?P&lt;branch>[^/]+)/
		  </p>
		</div>
              </div>
	    </fieldset>

	    <fieldset><legend>Repository Status</legend>
              <div class="form-row">
                <label>Root URL:</label>
                <div class="field">{{ user_asset.asset.repos.root_url|escape }}</div>
              </div>
              <div class="form-row">
                <label>Unique ID:</label>
                <div class="field">{{ user_asset.asset.repos.uuid|escape }}</div>
              </div>
              <div class="form-row">
                <label>Last updated:</label>
                <div class="field">{% if user_asset.asset.repos.last_update_time %}{{ user_asset.asset.repos.last_update_time|timesince }} ago
                                   {% else %}Never updated{% endif %}</div>
              </div>
              <div class="form-row">
                <label>Current revision:</label>
                <div class="field">{{ user_asset.asset.repos.last_revision }}</div>
              </div>
	    </fieldset>
	  {% endif %}

        </div>
      </li>
    </ol>
  </div>
  {{ block.super }}
{% endblock %}

{% block scripts-init %}
  {{ block.super }}
  autohideWithCheckbox("id_use_repository", "repository_details");
  {% if user_asset.asset.repos %}
    autohideWithLink("pinger_help_link", "pinger_help_text", 0);
    autohideWithLink("rev_url_help_link", "rev_url_help_text", 0);
    autohideWithLink("path_re_help_link", "path_re_help_text", 0);
  {% endif %}
{% endblock %}

